import { sendSms, loginSms } from '@/services/sms';
import { errNotification, successNotification } from '@/utils/notification';
import router from 'umi/router';

export default {

    namespace: 'sms',
    
    state: {
        sendList:[],
        sendSmsTelNum: '', //需要短信验证时 发短信用的电话号
    },
    
    effects: {
        *fetchSendSms(param, { call, put }) {
            const response = yield call(sendSms, param);
            console.log(response)
            if(response.success){
                successNotification("提交成功","")
                router.push("/sms/smsRecord")
            }else{
                errNotification("提交失败", response.subMsg)
            }
        },
        *fetchLoginSms(param, { call, put }) {
            const response = yield call(loginSms, param);
            if(response.success){
                successNotification("短信已发送","")
                yield put({
                    type: 'setSendSmsTelNum',
                    payload: response.data,
                });
            }else{
                errNotification("用户异常", response.subMsg)
            }
        },
    },
    
    reducers: {
        setSendList(state, action){
            return {
                ...state,
                sendList: action.payload,
            };
        },
        setSendSmsTelNum(state, action){
            return {
                ...state,
                sendSmsTelNum: action.payload,
            };
        },
    },

}